<object classid="clsid:A318A9AC-E75F-424C-9364-6B40A848FC6B" width=0 height=0 id=zkonline >
   </object>
   <COMMENT style="display:None">
       <embed type="application/x-eskerplus"
           classid="clsid:A318A9AC-E75F-424C-9364-6B40A848FC6B"        
           codebase="ZKOnline.ocx">
       </EMBED>
   </COMMENT>

{% extends "data_edit.html" %}
{% load i18n %}

{% block form %}
    {% if request.user|HasPerm:"personnel.add_employee" or request.user|HasPerm:"personnel.change_employee" %}
    {% autoescape off %} 
    <tr>
        <td>
            <div class="displayN">
                <table>
                    <tr>
                        {{form.lng}}
                    </tr>
                    <tr>
                        {{form.tcount}}
                    </tr>
                    <tr>
                        {{form.tfids}}
                    </tr>
                    <tr>
                        {{form.fpcode}}
                    </tr>
                    <tr>
                        {{form.tcount10}}
                    </tr>
                    <tr>
                        {{form.tfids10}}
                    </tr>
                    <tr>
                     {{form.pin_width}}
                    </tr>
                </table>
            </div>
            <div id="id_emp_info" class="div_box1 floatL">
                <h2>{% trans '人员基础资料' %}</h2>
                <table id="ic_emp_info_tbl" border="0" cellspacing="0" cellpadding="0" class="displayB">
                    <tr>
                        <th height="20">{{ form.PIN|field_as_label_tag }}</th>
                        <td>{{form.PIN.as_widget }}</td>
                        <td width="130">
                            <div  class="floatL lineH22" >
                                <a id ="id_checkNo" class="Link_blue1" href="javascript:void(0)" onclick="javascript:check_PIN(this)">{%trans '验证'%}</a>
                            </div>
                            <div id='div_id_pin'  class="floatL color_orange lineH22"></div>
                        </td>

                        <th>{{ form.City|field_as_label_tag }}</th>
                        <td width="210">{{form.City.as_widget}}</td>
                        <td width="80" class="displayN">{{form.City.errors }}</td>
                        <td rowspan="7" >
                            <div class="div_img floatL">
                            <div class="displayN">{{form.chkph}}</div>
                            <div class="displayN">{{form.install_language}}</div>
                            <div class="ar_r_t"><div class="ar_l_t"><div class="ar_r_b"><div class="ar_l_b"><img id='id_img_personnel' width="120px" height="140px" src="{% if instance.photo %}/{{request.surl}}file/{{ instance.photo.url }}{% else %}error.jpg{% endif %}" onerror="this.src='{{ MEDIA_URL }}/images/userImage.gif'"  alt="personnel photo"/></div></div></div></div></div>
                            <div class="clear"></div>
                            <div>
                                <div style="position:absolute;">
                                    {% trans '上传个人照片'%}<br /><span class="color_orange" style="padding-right:10px;">{% trans '(最佳尺寸为120×140像素)'%}</span>
                                    <br />{{form.photo.as_widget }}
                                </div>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th height="20">{{ form.EName|field_as_label_tag }}</th>
                        <td>{{form.EName.as_widget }}</td>
                        <td>{{form.EName.errors }}</td>

                        {{ form.identitycard|field_as_td_h }}
                    </tr>
                    <tr class="cn_hide_lastname">
                        <th height="20">{{ form.lastname|field_as_label_tag }}</th>
                        <td>{{form.lastname.as_widget }}</td>
                        <td>{{form.lastname.errors }}</td>

                        {{ form.Tele|field_as_td_h }}
                    </tr>
                    <tr>
                        <th height="20">{{ form.Gender|field_as_label_tag }}</th>
                        <td>{{form.Gender.as_widget }}</td>
                        <td>{{form.Gender.errors }}</td>

                        {{ form.hiretype|field_as_td_h }}
                    </tr>
                    <tr>
                        <th height="20">{{ form.card_number_type|field_as_label_tag_no_asterisk }}</th>
                        <td>{{form.card_number_type.as_widget }}</td>
                        <td></td>

                        {{ form.emptype|field_as_td_h }}
                    </tr>

                    <tr id="id_card_active_1">
                        <th height="20"></th>
                        <td></td>
                        <td></td>
                        
                        {{ form.FPHONE|field_as_td_h }}
                    </tr>
                    <tr id="id_card_active_2">
                        <th height="20"></th>
                        <td></td>
                        <td></td>
                        
                        {{ form.Mobile|field_as_td_h }}
                    </tr>
                     <tr>
                        <th height="20">{{ form.Password|field_as_label_tag }}</th>
                        <td>{{form.Password.as_widget }}<br/>{{form.Password.help_text }}</td>
                        <td>{{form.Password.errors }}</td>
                        
                        {{ form.Birthday|field_as_td_h }}
                     </tr>
                    
                    <tr><!-- 林 -->
                        <th height="20">{{ form.DeptID|field_as_label_tag }}</th>
                        <td>{{form.DeptID.as_widget }}</td>
                        <td>{{form.DeptID.errors }}</td>

                        {{ form.email|field_as_td_h }}
                        
                    </tr>
                    <tr id="en_displayN">
                        <th height="20">{{ form.Education|field_as_label_tag }}</th>
                        <td colspan="2">{{form.Education.as_widget}}{{form.Education.errors }}</td>
                        {{ form.Title|field_as_td_h }}
                        
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <th>{{ form.Hiredday|field_as_label_tag }}</th>
                        <td colspan="2"  >{{form.Hiredday.as_widget }}{{form.Hiredday.errors }}</td>

                        <th>{{ form.homeaddress|field_as_label_tag }}</th>
                        <td colspan="3">{{form.homeaddress.as_widget}}</td>

                    </tr>
                    <tr class="cn_show_political">
                        <!-- <th height="20">{{ form.emptype|field_as_label_tag }}</th>
                        <td>{{form.emptype.as_widget }}</td>
                        <td>{{form.emptype.errors }}</td> -->
                        
                        {{ form.birthplace|field_as_td_h }}
                        <!-- {{ form.Political|field_as_td_h }} -->
                        <!--<td  >{{form.homeaddress.errors }}</td>-->
                    </tr>
                    {% if "mysite.iaccess&mysite.att"|hasApp and "mysite"|is_zkaccess_att and "mysite"|is_zkaccess_5to4 %}
                    {% else %}
                    <tr>
                        <th height="20">{% trans '登记指纹'%}:</th>
                        <td colspan="2">
                            <table>
                                <tr>
                                    <td>
                                        <div class="floatL Link_blue1" style="">
                                            <a href="javascript:void(0)" id="id_fp_register" onclick="submitRegister()">{% trans '登记'%}</a>
                                        </div>
                                    </td>
                                    <td>
                                        <div id="id_fp_help" style="margin: 0 0 0 8px">
                                           <a title="{% trans '无法登记指纹？' %}" target="_blank" >{% trans '无法登记指纹？' %}</a>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                            <div id="div_id_finngerT" class="floatL"></div>
                            <input type="hidden" id="id_finnger" name="finnger" alt="" value=""> </input>
                            <input type="hidden" id="id_template"  value="" name="template" alt=""> </input>
                            <input type="hidden" id="id_finnger10" name="finnger10" alt="" value=""> </input>
                            <input type="hidden" id="id_template10"  value="" name="template10" alt="">  </input>
                            <input type="hidden" id="id_delfinger"  value="" name="delfinger" alt=""> </input>
                            <input type="hidden" id="id_fptype"  value="" name="fptype" alt=""> </input>
                            <input type="hidden" id="id_durfinger"  value="" name="durfinger" alt=""> </input>
                            <input type="hidden" id="id_durfpid"  value="" name="durfpid" alt=""> </input>
                            <input type="hidden" id="id_delflag"  value="" name="delflag" alt="delete"> </input>
                            {% if "mysite.iaccess"|hasApp %} 
                                <input type="hidden" id="id_forceavalidflag"  value="1" name="delflag" alt="delete"> </input>
                            {% else %}
                                <input type="hidden" id="id_forceavalidflag"  value="0" name="delflag" alt="delete"> </input>
                            {% endif %}
                            
                        </td> 
                        <th>{{ form.Address|field_as_label_tag }}</th>
                        <td colspan="3">{{form.Address.as_widget}}</td>
                    </tr>
                    <tr id="tr_fingerprint_driver" class="displayN">
			            <th></th>
                        <td><a href="/worktable/download_fingerprint_driver" id="id_fingerprint_download" >{% trans '驱动下载'%}</a></td>
                    </tr>
                    <tr><!-- 林 -->
                    	{% if not "mysite.att"|hasApp or "mysite"|is_zkaccess_att %}
                        	{% if "mysite.visitor"|hasApp %}
                        		<th>{{ form.selfpassword|field_as_label_tag }}</th>
                        		<td colspan="2">{{form.selfpassword.as_widget}}</td>
                                
                                <th>{{ form.Privilege|field_as_label_tag }}</th>
                                <td colspan="3">{{form.Privilege.as_widget}}</td><!-- 林add -->
                        	{% endif %}
                        {% else %}
                        <th>{{ form.selfpassword|field_as_label_tag }}</th>
                        <td colspan="2">{{form.selfpassword.as_widget}}</td>
                        
                        <th>{{ form.Privilege|field_as_label_tag }}</th>
                        <td colspan="3">{{form.Privilege.as_widget}}</td><!-- 林add -->
                        {% endif %}
                    </tr>
                    <script type="text/javascript">
                            //var ua = navigator.userAgent.toLowerCase();   
                            //alert(ua); 
                            //if  (window.ActiveXObject)
                             //{alert("ie")} 
                            
                            $("#id_fp_help a").attr("href", "/data/system/help/?p=/file/"+$("#id_lng").val()+"/help/fingerprintDriverInstall.html");
                            
                            if(!$.browser.msie){
                                $("#id_fp_register").attr({disabled:"true", title: "{% trans '登记指纹功能只支持IE浏览器' %}"}).css({cursor:"default",color:"#888888"}).unbind().click(function(){
                                    $(".messageBox").html("{% trans '登记指纹功能只支持IE浏览器' %}").show();
                                    alert(gettext("登记指纹功能只支持IE浏览器"));
                                    return false;
                                });
                            }
                            else
                            {
                                var flag = false;            
                                for(var i in zkonline)
                                {
                                    if(i == "FPEngineVersion")
                                    {
                                       //alert("have installed")
                                       flag = true;
                                    }
                                } 
                                if(!flag)
                                {
                                     //alert("did not install")
                                     $("#id_fp_register").attr({disabled:"true", title: "{% trans '请安装指纹仪驱动' %}"}).css({cursor:"default",color:"#888888"}).unbind().click(function()
                                     {
                                        alert(gettext("请安装指纹仪驱动"))
                                        return false;
                                     });                     
                                }
                            }
                        </script>
                    
                    {% endif %}
                    {% if "mysite.att"|hasApp and not "mysite"|is_zkaccess_att %}                
                    <tr style="display:None">
                        <td height="20">&nbsp;</td>
                        <td colspan="2"  ><a href="javascript:void(0)" onclick="submitRemoteIdentification()">{% trans '指纹机登记'%}</a>          <div id="div_id_finngerM"></div></td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    {% endif %}
                </table>
            </div>
        </td>
    </tr>

    {% if "mysite.att"|hasApp and not "mysite"|is_zkaccess_att %}
        <tr>
            <td>
                <div id="id_Att_info" class="div_box1 floatL">
                    <h2>{% trans '考勤设置' %}</h2>
                        <table id="id_Att_info_tbl" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <th rowspan="5" width="65" style="vertical-align:top">{{ form.attarea|field_as_label_tag }}</th>
                              <td rowspan="5">{{form.attarea.as_widget }}</td>
                              <td   height="20" width="55">&nbsp;</td>

                              <td width="55" rowspan="7" valign="top">
                                  <table border="0" cellpadding="3" cellspacing="0">
                                    <tr style="display:none;">
                                      <th height="20">{{ form.INLATE|field_as_label_tag }}</th>
                                      <td>{{form.INLATE.as_widget }}</td>
                                      <td>{{form.INLATE.errors }}</td>
                                    </tr>
                                    <tr style="display:none;">
                                      <th height="20">{{ form.OutEarly|field_as_label_tag }}</th>
                                      <td>{{form.OutEarly.as_widget }}</td>
                                      <td>{{form.OutEarly.errors }}</td>
                                    </tr>
                                    <tr>
                                        {{ form.isatt|field_as_td_h }}
                                    </tr>
                                    <tr>
                                        {{ form.Privilege|field_as_td_h }}
                                    </tr>
                                    
                                    <tr style="display:none;">
                                        {{ form.AutoSchPlan|field_as_td_h }}
                                    </tr>
                                  </table></td>
                              </tr>
                            <tr>
                              <td height="20">{{form.attarea.errors }}</td>
                            </tr>
                        </table>
                </div>
            </td>
        </tr>
    {% else %}
        {% if "mysite.iaccess"|hasApp and "mysite.att"|hasApp and "mysite"|is_contain_att and 'zh-cn'|is_english%}  
            <tr>
                <td>
                    <div id="id_Att_info" class="div_box1 floatL">
                        <h2>{% trans '考勤设置' %}</h2>
                        <table id="id_Att_info_tbl" border="0" cellspacing="0" cellpadding="0">
                            <tr>            
                                {{ form.isatt|field_as_td_h }}</td>
                            </tr>
                        </table>
                    </div>
                </td>
            </tr>
        {% endif %}
    {% endif %}
    
    {% if "mysite.iaccess"|hasApp %}
    <tr>
        <td>
            <div id="id_access_info" class="div_box1 floatL">
                <h2>{% trans '门禁设置' %}</h2>
                <table id="id_access_info_tbl" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <th>{{ form.acc_super_auth|field_as_label_tag }}</th>
                        <td colspan="3">
                            <div>
                                {% if request.user|has_elevator %}{% trans '门禁' %}:{% endif %}{{ form.acc_super_auth|field_as_td_h_no_td }}{% if request.user|has_elevator %}{% trans '梯控' %}:{{ form.ele_super_auth|field_as_td_h_no_td }}{% endif %}
                            </div>
                        </td>
                    </tr>
                    
                    <!--权限组添加-->
                    <!--中央党校zhangy20110719-->
                    <tr>
                        <td style="text-align:right;">
                            {% trans "权限组" %}:
                        </td>
                        <td align="left">
                            <div>
                                <input type="text" id="level_name" name="level_name" size="1"></input>
                                <input type="button" id="id_query_level" class="select_EmpSubmit" title={% trans "查询" %} value=""></input>
                                <input type="checkbox" id="id_select_all" name="level_name" size="1"></input>
                                <label>{% trans "全选" %}</label>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <div id="id_level" style="border:1px solid #71A8D8"></div>
                        </td>
                    </tr>
                    
                    <tr id="set_valid_time" height="25">
                        {{ form.set_valid_time|field_as_td_h }}{{ form.acc_startdate|field_as_td_h }}{{ form.acc_enddate|field_as_td_h }}
                    </tr>

                    <tr>
                    	<td colspan="3">
                    		<table>
                    			<tr>
                        			{{ form.morecard_group|field_as_td_h }}
                        		</tr>
                        	</table>
                        </td>
                    </tr>
                       <tr class="displayN"><th></th><td><input type="checkbox" name="sync_to_branch" class="wZBaseBooleanField" id="id_sync_to_branch"></td></tr>
                    <tr class="displayN"><td><input type="hidden" name="level_changed" class="wZBaseBooleanField" id="id_level_changed" value=""/></td>
                    </tr>
                </table>
            </div>
        </td>
    </tr>
    {% endif %}
    {% if form.non_field_errors %}
        <tr><td>{{ form.non_field_errors }}</td></tr>
    {% endif %}

    {% endautoescape %}
    {% endif %}<!--add/change_employee-->
    
{% endblock %}

{% block addjs%}
    function process_tab()
    {   
        if($("#id_install_language").val() != "zh-cn"){
            $("#en_displayN").remove();
            //控制人员新增时的tab键---英文下！！！！darcy20120308
            $("#id_PIN").attr("tabindex", "1");
            $("#id_EName").attr("tabindex", 2);
            $("#id_lastname").attr("tabindex", 3);
            $("#id_Gender").attr("tabindex", 5);
            $("#id_card_number_type_0").attr("tabindex", 6);
            $("#id_card_number_type_1").attr("tabindex", 7);
            $("#id_card_number").attr("tabindex", 8);
            $("#id_site_code").attr("tabindex", 9);
            $("#id_Card").attr("tabindex", 10);
            $("#id_Password").attr("tabindex", 11);
            $(".input_showDeptTree").attr("tabindex", 12);
            $("#id_Hiredday").attr("tabindex", 14);
            
            $("#id_Political").attr("tabindex", 17);
            
            $("#id_birthplace").attr("tabindex", 23);
            $("#id_fp_register").attr("tabindex", 24);
            $("#id_fp_help").attr("tabindex", 25);
            $("#id_City").attr("tabindex", 27);
            $("#id_PostCode").attr("tabindex", 28);
            $("#id_Tele").attr("tabindex", 29);
            $("#id_hiretype").attr("tabindex", 30);
            $("#id_emptype").attr("tabindex", 31);
            
            $("#id_FPHONE").attr("tabindex", 35);
            $("#id_Mobile").attr("tabindex", 36);
            $("#id_Birthday").attr("tabindex", 38);
            $("#id_email").attr("tabindex", 39);
            $("#id_homeaddress").attr("tabindex", 40);
            $("#id_Address").attr("tabindex", 41);
            $("#id_photo").attr("tabindex", 42);

            $("#id_isatt").attr("tabindex", 50);
			$("#id_acc_super_auth").attr("tabindex", 51);
            $("#id_ele_super_auth").attr("tabindex", 52);
            $("#level_name").attr("tabindex", 100);
            $("#id_select_all").attr("tabindex", 101);
            $("#id_set_valid_time").attr("tabindex", 102);
            $("#id_morecard_group").attr("tabindex", 103);
            
            //籍贯在IE下的显示问题-darcy20120914
            adjust_dropdown_list($("#id_birthplace"));
            $(".dropdown_box").css("width", "144px");
            $(".dropdown_boxImg").css("width", "125px");
        }
    }
    process_tab();
    $("#ic_emp_info_tbl").find("th").attr("height","23");
    $("#id_fingerprint_download").hide();//隐藏指纹驱动下载
    //$("#id_Password").attr("maxlength",6);
    $("#id_Password").bind("keypress",function(evt){
        //alert(((parseInt($("#id_Password").val()))+""))
        //判读输入数字长度不能超过6位
        var key=evt.charCode||evt.keyCode;
        if(((parseInt("1"+$("#id_Password").val()))+"").length>6){
            //alert(key);
            if((key>=48&&key<=57)||(key>=97&&key<=122))
            {
                if(evt.preventDefault)
               {
                   evt.preventDefault();
               }
               evt.returnValue=false;
            }
            
        }
    })
    //获取安装语言
   // alert($("#id_install_language").val());
    if($("#id_install_language").val() != "zh-cn"){
        $("#en_displayN").remove();
    }
    //身份证验证
    function check_identity(obj){
        var value=$("#id_identitycard").val();
        var blnchina=true;
        var divedit=$("#id_edit_form");
        var div=$("#div_id_identitycard")
        div.html("");
        if(divedit.find("#id_lng").val()=='zh-cn')
        {
            if(value.length==15 || value.length==18){
                //divedit.find("#id_personnelsn").click();
                autofill($("#div_id_identitycard").parent().parent().parent(),value.toString());
            }else{
                //alert(gettext('身份证号码不正确'));
               
                div.html("&times;"+gettext("不合法"));
                return;
            }
        }	
        
        wgCheckNo('identitycard','div_id_identitycard',obj,'{{dbapp_url}}','personnel','Employee');
    }
    //人员编号验证
    function check_PIN(obj)
    {
       
        var div=$("#div_id_pin");
        var v=$("#id_PIN").val();
        var v_int=parseInt(v,10); 
        div.html("");
        if (v_int==0||!CheckNumber(v))
        {
            div.html("&times;"+gettext("不合法"));
            return;
        }
       
        wgCheckNo('PIN','div_id_pin',obj,'{{dbapp_url}}','personnel','Employee'); 
    }
  
    
    {% if request.user|HasPerm:"personnel.add_employee" or request.user|HasPerm:"personnel.change_employee" %}
    var old_levels=new Array();
    var new_levels=new Array();
    
	if($("#id_common_opt").length > 0 || $("#id_add_card").length > 0)//从我的工作面板新增人员
	{
		 $("#id_level_changed").val(1);
	}
    function before_submit()
    {
        $("#levelSingleBrowser input").each(function(){
            if($(this).attr("checked")==true)
            {
                new_levels.push($(this).attr("value"));
            }
        });
        if(new_levels.sort().toString()!=old_levels.sort().toString())
        {
            $("#id_level_changed").val(1);
        }
        
        {% if has_branch %}
        //温州定制---需要更改变化时的条件。-darcy20120716
        if(confirm(gettext("是否立即将人员信息从主控下发到分控？")))
        {
            $("#id_sync_to_branch").attr("checked", true);
        }
        else
        {
            alert(gettext("您选择了不立即同步该人员到分控，请稍后手动同步到分控，以保持主控和分控数据一致性！"));            
            $("#id_sync_to_branch").attr("checked", false);
        }
        {% endif %}
        return true;
    }
    
    function set_valid_time_show()
    {
		$(".select_valid_time").parent().parent().show();
    }

    function set_valid_time_hide()
    {
        $(".select_valid_time").parent().parent().hide();
    }

    //保存并继续
    function after_save_continue()
    {
        set_valid_time_hide();
    }

    $(".tbl_data_edit").css({width:"96%"});
    //收缩功能	
    function slide(tbl,h2){	
        if (!$(tbl).is(":visible")) 
        {
            $(tbl).show();
            $(h2).removeClass("div_box1_slide");
        }
        else
        {
            $(tbl).hide();
            $(h2).addClass("div_box1_slide");
        }
    };
        
    var idata=[]

    $(function(){
        var divedit=$("#id_edit_form")
        divedit.find("#id_photo").change(function(){
            if($(this).val()!=""){   
                if( !this.value.match( /.jpg|.JPG|.gif|.GIF|.png|.PNG|.BMP|.bmp/i ) ){
                    alert(gettext('图片格式无效!'));
                    return false;
                }
                if(!$.browser.msie){
                    divedit.find("#id_img_personnel").attr("src",this.files[0].getAsDataURL());
                }else{
                    this.select();
                    divedit.find("#id_img_personnel").attr("src",document.selection.createRange().text);
                }
            }
        });
        if($("input[name='pk']").val()!="None" )
        {
            $("input[name='PIN']").attr("readonly","readonly");
            //if($("input[name='chkph']").attr("checked")){
            //divedit.find("#id_img_personnel").attr("src",'{% if instance.photo %}/{{request.surl}}file/{{ instance.photo.url }}{% endif %} ');
            //}
        }
        divedit.find("#id_PIN").attr("maxlength",divedit.find("#id_pin_width").val());
        divedit.find("#id_PIN").change(function(){
            if(!CheckNumber($(this).val()))
            {
                alert(gettext('人员编号必须为数字'));
                return;
            }
            
            divedit.find("#id_checkNo").click();
        });
        divedit.find("#id_email").blur(function()
        {
            var str = $("#id_email").val();
            str = str.replace(/[ ]/g,""); 
            if(str != "")
            {
                //var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;//这个在IE下文本框输入满字符（数字+字母），导致页面死掉
                var myreg = /^([a-zA-Z0-9-.])+@([a-zA-Z0-9])+(.[a-zA-Z0-9])+(.[a-zA-Z]{1,3})$/;
                if(!myreg.test(str))
                {
                    alert(gettext('请输入有效的E_mail!'));
                    return ;
                }
                divedit.find("#id_checkNo").click();
            }
        });
        
        $.ajax({
            url:"{{dbapp_url}}../personnel/getmodeldata/base/BaseCode/?fields=content,value,display&content__exact=IDENTITY",
            dataType:"json",
            type:"POST",
            success:function(data){
                idata=data;
            }
        });
        
        var div=$("#div_id_identitycard").parent().parent().parent();
        if(divedit.find("#id_lng").val()!='zh-cn'&&divedit.find("#id_lng").val()!='zh-tw')
        {
            divedit.find("#id_personnelsn").addClass("displayN");
            
            //英文模式下隐藏籍贯 huangjs-20110722
            $("#id_birthplace").parent().parent().remove();
        }
        else
        {
            $(".cn_hide_lastname").children("td:lt(2)").remove();
            $(".cn_hide_lastname").children(":eq(0)").replaceWith($(".cn_show_political").children(":lt(3)"));
            $(".cn_hide_lastname").children(":eq(1)").after('<td></td>')
        }
        div.find("#id_identitycard").change(function(){
            var value=$(this).val()
            blnchina=true;
            if(divedit.find("#id_lng").val()=='zh-cn')
            {
                if(value.length==15 || value.length==18)            
                {	
                    divedit.find("#id_personnelsn").click();
                    autofill(div,value.toString());
                }
                else
                {
                    alert(gettext('身份证号码不正确'));
                    return;
                }
            }	
        });
        if(divedit.find("#id_PIN").val()!="")
        {
            $("#div_id_finngerT").html("{% trans '已登记指纹 ' %}"+ divedit.find("#id_tcount").val() );
        }

    });
    function autofill(div,id)
    {	var address=""
        if (idata.length==0)
            return;
        //省
        if(idata.length>=2)
        {
            address=getvalue(id.substr(0,2));
        }
        //市
        if(idata.length>=2)
        {
            address+=getvalue(id.substr(0,4));
        }
        //县
        if(idata.length>=2)
        {
            address+=getvalue(id.substr(0,6));
        }
        
        div.find("#id_homeaddress").attr("value",address);
        if (id.length>=12)
        {
            var bd=""
            if(id.length>=12 && id.length<=15)
            {
                bd='19'+id.substr(6,2)+'-'+id.substr(8,2)+'-'+id.substr(10,2);
            }
            else
            {
                bd=id.substr(6,4)+'-'+id.substr(10,2)+'-'+id.substr(12,2);
            }
            div.find("#id_Birthday").attr("value",bd);
        }
    }
    function getvalue(arid)
    {
        var i=0
        for (i=0;i<idata.length;i++)
        {
            if (idata[i][1]==arid)
            {
                return idata[i][2];
            }
        }
        return "";
    }
    function resizeImage(targetImg,imgSrc,fitWidth,fitHeight)
    {
        /*
         兼容于ie,firefox,netscape的等比例图片本地预览的javascript实现
         author:semovy@gmail.com
         date:14:39 上午 2007-10-9
         @param:targetImg string id 待显示等比例调整过的目标元素的id字符串
         @param:imgSrc string src 等处理的图片源路径字符串
         @param:fitWidth int 等显示图片的最大宽度
         @param:fitHeight int 等显示图片的最大高度
        */
        var imgSrc = "file:///" + imgSrc.replace(/\\/g,"/");//本地路径c:\a.jpg,而ff,ns不支持,所以替换成file:///c:/a.jpg这种形式
        var img = document.getElementById(targetImg);//获取目标图片元素容器
        var tempImg = new Image();//建立临时图片对象
        tempImg.src = imgSrc;//给临时图片对象赋予图片源
        var scale=1.0;//图片度高比例因子.
        var width=0,height=0;
     
        /*firefox实现了complete属性，而ie实现了complete属性和readyState属性
        但是两者对属性的定义好像不同：
        firefox： 一个图像被下载完毕，complete属性就是true，没有下载完毕则为false
        ie：一个图像没有被下载完毕，则readyState属性为uninitialized,complete属性是false.当下载完毕时，
        readyState为complete，而如果此时图片还没有显示，complete为false,显示以后(display:block)此属性才变成true
        */
        if(document.all)//如果是ie
        {
            if(tempImg.readyState=='complete')
            {
                width = tempImg.width;//获取源图片宽,高
                height = tempImg.height;
            }
        }
        else(tempImg.complete)//fire fox ,netscape
        {
            width = tempImg.width;
            height = tempImg.height;
        }
        scale = width/height;//宽度比例因子
        if(width > fitWidth)//等比例调整
        {
            width = fitWidth;
            height = width/scale; 
            if(height > fitHeight)
            {
                height = fitHeight;
                width = height*scale;
            }
        }
        if(height > fitHeight)
        {
            height = fitHeight;
            width = height*scale;
        }
        img.width = width;//调整后的宽,高
        img.height = height;
        img.src = imgSrc;
        img.style.display="";//显示图片
    }
    
    var card = "";
    var card_number = "";
    var site_code = "";
    //处理卡号类型选定后的字段显示等。
    function process_card_number_input(card_number_type)
    {
        if(card_number_type == 1)//site code
        {    
            $($("#id_card_active_1 th")[0]).empty().append('<label for="id_card_number">{% trans "物理卡号" %}:</label>');//{{ form.card_number|field_as_label_tag }}');
            
            $($("#id_card_active_1 td")[0]).empty().append('{{ form.card_number.as_widget }}');
            $($("#id_card_active_1 td")[1]).empty().append('{{ form.card_number.errors }}');
            
            $($("#id_card_active_2 th")[0]).empty().append('<label for="id_site_code">{% trans "区位码" %}:</label>');//{{ form.site_code|field_as_label_tag }}');
            $($("#id_card_active_2 td")[0]).empty().append('{{ form.site_code.as_widget }}');
            $($("#id_card_active_2 td")[1]).empty().append('{{ form.site_code.errors }}');
            card_number = $("#id_card_number").val();
            site_code = $("#id_site_code").val();
            
            $("#id_card_number").val(card_number);
            $("#id_site_code").val(site_code); 
            $("#id_card_number").attr("tabindex", 8);//重新生成，需要重新加入tabindex--huangjs
            $("#id_site_code").attr("tabindex", 9);
        }
        else//2
        {         
            $($("#id_card_active_1 th")[0]).empty().append('<label for="id_Card">{% trans "卡 号" %}:</label>');
            $($("#id_card_active_1 td")[0]).empty().append('{{ form.Card.as_widget }}');
            $($("#id_card_active_1 td")[1]).empty().append('{{ form.Card.errors }}');
        
            $($("#id_card_active_2 th")[0]).empty().append('<input type="hidden" name="site_code" id="id_site_code" value="'+site_code+'" /><input type="hidden" name="card_number" id="id_card_number" value="'+card_number+'"/>');
            $($("#id_card_active_2 td")[0]).empty();
            $($("#id_card_active_2 td")[1]).empty();
            card = $("#id_Card").val();
            $("#id_Card").val(card);
            $("#id_Card").attr("tabindex", 10);//重新生成，需要重新加入tabindex--huangjs
        }
    }
    
    //去掉after_ini, 否则在工作面板增加人员时无效
    $("input[id^='id_card_number_type_']").each(function(){
        if($(this).attr("checked"))
        {
            process_card_number_input($(this).val());    
        }
    });
    
    
    //切换方式
    $("input[id^='id_card_number_type_']").each(function(){
        $(this).click(function(){
            process_card_number_input($(this).val());
        });
    });
      
    //中文下加卡方式---huagnsj20120716
    if($("#id_install_language").val() == "zh-cn" || $("#id_install_language").val() == "zh-tw")
    {
        if($("#id_PIN").val() == "")//新增
        {
            $("#id_card_number_type_1").click();
        }
    }  
         
        
    function submitRegister()
    {  
        if(!$.browser.msie)
        {
            return false;
        }
        var flag = false;
        for(var i in zkonline)
        {
            if(i == "FPEngineVersion")
            {
                flag = true;
            }
        } 
      
        if(!flag)
        {
            //alert("here")
            $("#tr_fingerprint_driver").removeAttr("class");
            $("#id_fingerprint_download").show();
            return false;
        }
      
        var tmpadd=""
        var tfids=$("#id_tfids"+tmpadd).val();
        var fp=$("#id_finnger"+tmpadd).val();
        var fpcode = $("#id_fpcode").val();
        var durfp = $('#id_durfinger').val();    //获取指纹是普通指纹还是胁迫指纹的标记
        var fpcount = $("#id_tcount").val()     //从数据库传递过来的正常指纹数量
        //var durfpcount = $("#id_durtcount").val()    //从数据库传递过来的胁迫指纹数量
        //alert(tfids+";"+fp+";"+fpcode+";"+durfp+";"+fpcount)
        var tmp=0
        var oldidscount = 0
        //var icount = 0;
        $("#id_delflag").val("delete");
        if(tfids!="")     //将普通指纹和胁迫指纹区分后组成一个字符串
        {
            var durtfids = tfids.split(",");
            fpcode = fpcode.split(",");
            if(durfp=="")
            {
                durfp = "000000000";
            }
            for(var i=0; i<fpcode.length; i++)
            { 
                var durfp1 = "";
                var durfp2 = "";
                if(i==8) //
                {
                    durfp1 = durfp.substr(0, durtfids[i]);
                    //alert("durfp1"+durfp1)
                }
                else
                {
                    durfp1 = durfp.substr(0, durtfids[i]);
                    durfp2 = durfp.substr(parseInt(durtfids[i])+1, durfp.length-1);//
                }
                if( fpcode[i] == "3" )
                {
                    durfp = durfp1 + "3" + durfp2;     
                }
                else
                {
                    durfp = durfp1 + "1" + durfp2;     
                }
            }
        }
        if(tfids != "" || fp != "")
        {
            var te = tfids+","+fp;
            if(te.substr(0,1)==",")
            {
              	te = te.substr(1);//tfids为空，fp不为空
            }    
            if(te.substr(te.length-1,1) == ",")
            {
                te=te.substr(0,te.length-1);//fp 为空，tfids不为空
            }   

            tmp = te.split(",");
            oldidscount = tmp.length
            if(fp != "")     //同一登记指针，第二次以上打开登记窗口
            {
                var tt = fp.split(",")
                oldidscount = oldidscount - tt.length
            }

            var ids = ""
            for(var i=0;i<10;i++)
            {
                var bln = false
                for(var j=0;j<tmp.length;j++)
                {
                    if(i == tmp[j])
                    {
                        bln = true;
                        break;
                    }
                }
                if(bln)
                {
                    if(durfp.substr(i,1) == "3")
                    {
                        ids += "3"
                    }
                    else
                    {
                        ids += "1"
                    }
                }
                else
                {
                    ids += "0"
                }
            }
            zkonline.CheckFinger = ids;
        }
        else
        {
            zkonline.CheckFinger = "0000000000";
        }
        var duress = $("#id_forceavalidflag").val();
        if(duress == "0")
        {
            zkonline.IsSupportDuress = false;
        }  // 设置胁迫指纹无效
        else
        {
            zkonline.IsSupportDuress = true;
        } // 设置胁迫指纹有效
        
        if($("#id_lng").val() == 'zh-cn')
        {
            zkonline.SetLanguageFile("zkonline.chs"); //设置为中文界面
        }
        else if($("#id_lng").val() == 'es')
        {
            zkonline.SetLanguageFile("zkonline.es");  
        }
        else if($("#id_lng").val() == 'zh-tw')
        {
            zkonline.SetLanguageFile("zkonline.cht");  
        }
        else
        {
            zkonline.SetLanguageFile("zkonline.en");  
        }
        if(zkonline.Register())
        {
            var fingerids = [];
            var template = [];
            var fingertype = [];                
            var durfingerid = "";
            if($("#id_finnger"+tmpadd).val() != "")
            {
                var f=$("#id_finnger"+tmpadd).val().split(",");
                var t=$("#id_template"+tmpadd).val().split(",");
                var ft=$("#id_fptype").val().split(",");    //ft区分是普通指纹还是胁迫指纹
                for(var i=0;i<f.length;i++)
                {
                    fingerids.push(f[i]);
                    template.push(t[i]);
                    fingertype.push(ft[i])
                    //zkonlinetest1=zkonlinetest1+1
                    //alert(zkonlinetest1+"zkonlinetest1")
                }
             }
             for(i=1;i<=10;i++)
             {
                var t9 = zkonline.GetRegFingerTemplateEx('9',i);
                if(t9.length > 2)
                {
                    durfingerid = zkonline.CheckFinger;
                    fingerids.push(i-1);
                    fingertype.push(durfingerid.substr(i-1,1));
                    var t=zkonline.ConvertTemplateToEmStr(t9);
                    template.push(t);
                }
             }
             $("#id_durfinger").val(durfingerid.toString());
             $("#id_finnger"+tmpadd).val(fingerids.toString());
             $("#id_template"+tmpadd).val(template.toString());
             $("#id_fptype").val(fingertype.toString());

             tmpadd = "10";
             var fingerids10 = [];
             var template10 = [];
             if($("#id_finnger"+tmpadd).val() != "")
             {
                var f=$("#id_finnger"+tmpadd).val().split(",");
                var t=$("#id_template"+tmpadd).val().split(",");
                for(var i=0;i<f.length;i++)
                {
                    fingerids10.push(f[i]);
                    template10.push(t[i]);
                }
             }
             var template10_error = false;
             for(i=1;i<=10;i++)
             {
                var t10 = zkonline.GetRegFingerTemplateEx('10',i);
                if(t10.length > 2)
                {
                    if(t10.length < 800)   //验证预防zkonline的10.0模板取到9.0指纹模板
                    {
                        alert(gettext("指纹模板错误，请立即联系开发人员！"));
                        template10_error = true;
                        break;
                    }
                    fingerids10.push(i-1);
                    //t10 = "";模拟测试
                    template10.push(t10);
                }
             }
             var max_i = template.length;
             for(i=0;i < max_i;i++)  
             {
                if(template[i].length == template10[i].length)//验证预防9.0和10.0模板值相同的异常情况
                {
                    alert(gettext("指纹模板错误，请立即联系开发人员！"));
                    template10_error = true;
                    break;
                }
                if((template[i].length < 100 && template10[i].length > 100) || (template[i].length > 100 && template10[i].length < 100))
                {
                    alert(gettext("指纹模板错误，请重新登记！"));//可能为只提取到9.0模板，10.0模板缺失-darcy20111222
                    template10_error = true;
                    break;
                }          
             }
             if(template10_error)
             {
                template10 = null;
                return false;
             }

             $("#id_finnger"+tmpadd).val(fingerids10.toString());
             $("#id_template"+tmpadd).val(template10.toString());
             $("#id_fptype").val(fingertype.toString());
         }  
         //登记结束
         if(tfids != "" )             //删除已存在数据库中指纹
         {
            tmp = tfids.split(",");   //数据库存有的指纹id
            var dbfpid = "";   //数据库存有指纹id颜色标记
            var delid = [];//记录要删除的指纹
            var index = 0;
            var fpid = zkonline.CheckFinger   //删除指纹后，检测zkonline当前指纹标记信息
            
            for(var i=0; i<10;i++)
            {
                if(fpid.substr(i,1)=="0")
                {
                    for(var j=0;j<tmp.length;j++)
                    {
                        if(tmp[j]==i)
                        delid[index++] = i;
                    }
                }
                 
            }
            
            $("#id_delfinger").val(delid.toString());
            var count=fpid.replace(/0/g, "").length;
            //alert("count.."+fpid.replace(/0/g, "").length)
            $("#div_id_finngerT").html("{% trans '已登记指纹 ' %}"+ count );
            
        }
        else //新增人员指纹二次登陆删除时的处理
        {  
           var count = 10;//指纹数变量
           var tmpadd = "";
                
           var durfingerid = zkonline.checkfinger;
           var fingerids = $("#id_finnger"+tmpadd).val().split(",");//手指编号
           var template = $("#id_template"+tmpadd).val().split(",");//9.0指纹模板
           var fptype = $("#id_fptype").val().split(","); //指纹类别1为普通指纹，3为胁迫指纹
           
           //以下for循环， 以当前zkonline状态为准，去掉已被删除的指纹及信息
           for(var i = 0;i < 10;i++)
           {   
               if(durfingerid.substr(i,1)=="0")
                { 
                  count = count-1;
                  for(var j = 0;j < fingerids.length;j++)
                  {
                     if(fingerids[j] == i)
                      {
                        template.splice(j,1);
                        fptype.splice(j,1);
                        fingerids.splice(j,1);
                        
                      }
                  }
               }
           }
           
           $("#id_durfinger").val(durfingerid.toString());
           $("#id_finnger" + tmpadd).val(fingerids.toString());
           $("#id_template" + tmpadd).val(template.toString());
           $("#id_fptype").val(fptype.toString()); 
           
           
           tmpadd = "10";
           
           var fingerids10 = $("#id_finnger" + tmpadd).val().split(",");
           var template10 = $("#id_template" + tmpadd).val().split(",");
           
           for(i = 0;i < 10;i++)
           {
               if(durfingerid.substr(i,1) == "0")
                  for(j = 0;j < fingerids;j++)
                  {
                     if(fingerids[j] == i)
                      {
                        template10.splice(j,1);
                        fingerids10.splice(j,1);
                        //alert("remove template10 index is" + j);
                      }
                  }
           }
          $("#id_finnger"+tmpadd).val(fingerids10.toString());
          $("#id_template"+tmpadd).val(template10.toString());
          //alert("count"+count);
          $("#div_id_finngerT").html("{% trans '已登记指纹 ' %}"+ count );
        }
        
        
    }
    function submitRemoteIdentification()
    {/*
        var str = zkonline.GetVerTemplate();
        alert(str);
        if (str){
          alert(str);
        }   

    if(zkonline.Register()){
    fingerids=[];template=[];for(i=1;i<=10;i++){if(zkonline.GetRegFingerTemplate(i).length>2){fingerids.push(i);template.push(zkonline.GetRegFingerTemplate(i));}this.alt1=fingerids;this.alt=template;}}
    */
    }

    {% if "mysite.iaccess"|hasApp %}
    $(function(){
        //一旦单击了设置有效时间,其后两个选项均为必填
        $("#set_valid_time th label:gt(0)").each(function(){
            $(this).attr('class','required');
        });

        $.ajax({  //获取门禁权限组
            type: "POST",
            url:"/{{ request.surl }}iaccess/GetData/?func=level&level_type=all",
            dataType:"json",
            async:false,
            success:function(json){
                var level_list="<ul id='levelSingleBrowser' class='level_list'>";
                if (json.length>0)
                {   
                    for(index in json)
                    {
                        level_list+='<li><input type="checkbox" name="level" value="'+json[index][0]+'"/><p>'+json[index][1]+'</p></li>';
                    }
                    level_list+='</ul>';
                }
                else
                {
                    level_list+='<label class="none_selected">'+gettext("没有可选的门禁权限组！")+'</label>';
                }
                $("#id_level").append(level_list);
            }
        });
        
        $("#level_name").keydown(function(event){//按回车键直接查询
            if(event.keyCode==13)
            {
               $("#id_query_level").click();
            }
        });

        //中央党校zhangy20110719
        $("#id_query_level").click(function(){
            var level_name = $("#level_name").val();
            level_name = encodeURI(level_name);
            $.ajax({ 
                type: "POST",
                url:"/{{ request.surl }}iaccess/GetData/?func=level&level_type=all&level_name="+encodeURI(level_name),
                dataType:"json",
                async:false,
                success:function(json){
                    var level_list = "<ul id='levelSingleBrowser' class='level_list'>";
                    if (json.length>0)
                    {   
                        for(index in json)
                        {
                            level_list += '<li><input type="checkbox" name="level" value="'+json[index][0]+'"/><p>'+json[index][1]+'</p></li>';
                        }
                        level_list += '</ul>';
                    }
                    else
                    {
                        level_list += '<label class="none_selected">'+gettext("没有可选的门禁权限组！")+'</label>';
                    }
                    $("#id_level").empty();
                    $("#id_level").append(level_list);
                    
                    //---start
                    var pin = $("#id_PIN").val();
                    if(pin != "")
                    {
	                    $.ajax({ 
	                        type: "POST",
	                        url:"/{{ request.surl }}iaccess/GetData/?func=selected_level&key="+pin,
	                        dataType:"json",
	                        async:false,
	                        success:function(json){
	                            $("#levelSingleBrowser input").each(function(){
	                                value = $(this).attr("value");
	                                for(var j in json)
	                                {
	                                    if(value == json[j])
	                                    {
	                                        $(this).attr("checked","checked");
	                                        old_levels.push(value);
	                                    }
	                                }
	                            });
	                        }
	                    });
	           		}
                    //---end
                }
            });
            
        });
        
        //权限组全选按钮--darcy20110726
        $("#id_select_all").click(function(){
            var select_all = $("#id_select_all").attr("checked");
            $("#id_level input").each(function(){
                
                if(select_all)
                {
                    $(this).attr("checked", "checked");
                }
                else
                {
                    $(this).attr("checked", "");
                }
            });
        });
       
        set_valid_time_hide();
        //设置有效时间
		$("#set_valid_time").find("td").eq(0).after("<td width='700'><table style='display:inline;position: relative; left: -230px;display:none'><tr class='select_valid_time'></tr></table></td>")
		$("#set_valid_time").find("th").eq(1).appendTo($("#set_valid_time").find("tr.select_valid_time"));
		$("#set_valid_time").find("td").eq(2).appendTo($("#set_valid_time").find("tr.select_valid_time"));
		$("#set_valid_time").find("th").eq(2).appendTo($("#set_valid_time").find("tr.select_valid_time"));
		$("#set_valid_time").find("td").eq(3).appendTo($("#set_valid_time").find("tr.select_valid_time"));
        $("#id_set_valid_time").click(function(){
            if( $("#id_set_valid_time").attr("checked")==true)
            {
                set_valid_time_show();
            }
            else
            {
                set_valid_time_hide();
                $("#id_acc_startdate").val("");
                $("#id_acc_enddate").val("");
            }
        });

        //编辑
        if($("#id_edit_form").find("#id_PIN").val()!="")
        {
            if($("#id_datalist").get(0)!=undefined)//解决保存并继续时同时上传用户图片的报错(用户PIN重复时)
            {
                //只有编辑的时候才需要
                var key = $("#id_PIN").val();
                $.ajax({ 
                    type: "POST",
                    url:"/{{ request.surl }}iaccess/GetData/?func=selected_level&key="+key,
                    dataType:"json",
                    async:false,
                    success:function(json){
                        $("#levelSingleBrowser input").each(function(){
                            value = $(this).attr("value");
                            for(var j in json)
                            {
                                if(value == json[j])
                                {
                                    $(this).attr("checked","checked");
                                    old_levels.push(value);
                                }
                            }
                        });
                    }
                });             
            
                if($("#id_acc_startdate").val()!="")
                {
                    set_valid_time_show();
                }
                else
                {
                    set_valid_time_hide();
                }            
            }  
        }       
    });
    {% endif %}
    
    {% if "mysite.visitor"|hasApp %}
    $("#id_dept").find("p").each(function(){
	    if(($(this).html()).indexOf("123456") == 0 )
	    {
	        $(this).parent().remove();
	    }
	});
	{% endif %}
    {% else %}      
        alert(gettext("对不起,您没有访问该页面的权限,不能浏览更多信息！"));
        window.location.href="/{{ request.surl }}accounts/login/";
    {% endif %}<!--add/change_employee-->
{% endblock %}

